use std::env;
use std::path::PathBuf;
use std::io::Result;

fn main() -> Result<()> {
    // Tell cargo to rerun this script if any of these files change
    println!("cargo:rerun-if-changed=protos/actor.proto");
    println!("cargo:rerun-if-changed=protos/remote.proto");
    println!("cargo:rerun-if-changed=protos/cluster.proto");
    println!("cargo:rerun-if-changed=protos");
    
    // Get the output directory for the build
    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
    
    // Configure the protobuf compilation
    let config = prost_build::Config::new();
    
    // Use the tonic build with our configuration
    tonic_build::configure()
        .build_client(true)
        .build_server(true)
        .file_descriptor_set_path(out_dir.join("proto_descriptor.bin"))
        .compile_with_config(
            config, 
            &[
                "protos/actor.proto",
                "protos/remote.proto",
                "protos/cluster.proto",
            ], 
            &["protos"]
        )?;
    
    Ok(())
} 